import React from 'react'
import { Table } from 'antd';
const { Column } = Table;


class Timi extends React.Component{
    constructor(props){
        super(props)
        this.state = {
            dataSource:JSON.parse(localStorage.getItem('data'))||
            [
                {
                    name:"康康",
                    sex:"男",
                    age:18,
                    phone:17719290592,
                    delete:"删除"
                },
                {
                    name:"111",
                    sex:"男",
                    age:18,
                    phone:123456,
                    delete:"删除"
                },
                {
                    name:"333",
                    sex:"女",
                    age:18,
                    phone:33333333333,
                    delete:"删除"
                },
                {
                    name:"222",
                    sex:"男",
                    age:18,
                    phone:22222222222,
                    delete:"删除"
                },
                {
                    name:"666",
                    sex:"女",
                    age:18,
                    phone:66666666666,
                    delete:"删除"
                },
                {
                    name:"888",
                    sex:"男",
                    age:18,
                    phone:88888888888,
                    delete:"删除"
                },
                {
                    name:"000",
                    sex:"女",
                    age:18,
                    phone:1000000,
                    delete:"删除"
                },
                {
                    name:"777",
                    sex:"男",
                    age:18,
                    phone:77777777777,
                    delete:"删除"
                }
            ],
            showData:[]
        }
    }

    render(){
        return (
            <div>
                <Table dataSource={this.state.dataSource} columns={this.state.columns}
                    pagination={{ pageSize:5}}>
                        <Column title="姓名" dataIndex="name" key="name" />
                        <Column title="性别" dataIndex="sex" key="sex" />
                        <Column title="年龄" dataIndex="age" key="age" />
                        <Column title="电话" dataIndex="phone" key="phone" />
                        <Column title="操作" dataIndex="delete" key="delete" render={(text,record,index) => (
                          <a onClick={()=>{
                              console.log(text)
                              console.log(record)
                            this.state.dataSource.splice(index,1)
                              
                              var tempItems = this.state.dataSource
                              console.log(111111,tempItems)
                              localStorage.setItem('data',JSON.stringify(tempItems))
                            this.setState({
                                dataSource:JSON.parse(localStorage.getItem('data'))
                            })
                          }}>删除</a>
                      )}/>
                </Table>
            </div>
        )
    }
}

export default Timi;